home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / utilitys / 93 / makersh / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-10-12  |  8.0 KB  |  261 lines

  1. /*
  2.    This program may be freely
  3.   distributed , copied,and modified so long
  4. as a fee is not charged. However,
  5. I reserve all rights available to
  6. me under The Copyright Act.
  7. If you find any bugs please feel free to contact me.
  8.   David DeGeorge
  9.   Princeton,New Jersey
  10.   March 1987
  11.  
  12. USENET:  ....princeton!idacrd!dld
  13. COMPUSERVE: 74176,3210
  14. GENIE: DEGEORGE
  15. */
  16.  
  17. #define MAIN
  18. #include "makersh.h"
  19. #include "globals.h"
  20. #ifdef GEM
  21.     main()
  22.   {
  23. #else
  24.       main(argc,argv)
  25.       char **argv;
  26. {
  27. #endif         
  28.      int i,*p,j;
  29.          char *q,*r1,mesag[80];
  30.          int oneflag;
  31.          int size;
  32.          long where,z,w,*r,lseek();
  33.          
  34. #ifdef GEM         
  35.         begin();
  36.         getfiles(&in,&out);        
  37. #else
  38.           if ( argc != 3)       /* get input and output */
  39.              error("",USAGE);
  40.          if(( in  = fopen(argv[1],"rb"))== NULL){
  41.            sprintf(mesag,"Can't open %s for reading\n",argv[1]);
  42.            error(mesag,FATAL);
  43.         }
  44.         
  45.         if((out = fopen(argv[2],"w"))==NULL){
  46.            sprintf(mesag,"Can't open %s for writing\n",argv[2]);
  47.            error(mesag,FATAL);
  48.         }
  49.         if ( access(argv[2],EXISTS) == 0){
  50.           sprintf(mesag,"%s exists",argv[2]);
  51.           error(mesag,WARN);
  52.         }
  53. #endif                     
  54.              
  55.          size = fread(&rheader,1,sizeof(rheader),in);    /* read the header */
  56.              
  57.          if ( size != sizeof(rheader))
  58.              error("Error in|reading header",FATAL);
  59.              /* check if resource file */
  60.              
  61.          if((long)(rheader.rsh_rssize) != lseek(fileno(in),0L,2))
  62.                error("Resource file is not|the correct length",WARN);
  63.                
  64.          stradds =(long *)malloc(MAXSTR*4);
  65.          nullnes(stradds,"Space for string addresses"); 
  66.  
  67.            
  68.   
  69.          head = malloc(rheader.rsh_rssize);
  70.          nullnes(head,"Resource file");
  71.          fseek(in,0L,0);
  72.          
  73.          /* Read the whole file into memory */
  74.          
  75.          fread(head,1,rheader.rsh_rssize,in);
  76.          
  77. #ifdef GEM     
  78.          makeitems();
  79.          display();
  80. #endif         
  81.          bbadds = (long *)malloc(4*rheader.rsh_nbb);
  82.          
  83.           nullnes(bbadds,"Bitblock addresses");
  84.          objs = (OBJECT *)( head + rheader.rsh_object);    
  85.          teds = (TEDINFO *)( head + rheader.rsh_tedinfo);
  86.          bitblks = (BITBLK *)( head + rheader.rsh_bitblk);
  87.          iconblks = ( ICONBLK *)(head + rheader.rsh_iconblk);
  88.          
  89.    /* lets do the strings   */     
  90.         q = ( char *) ( head + rheader.rsh_string);
  91.         r1 = ( char *) ( head + rheader.rsh_imdata);
  92.          j = 0;        
  93.         oneflag = 1;  /* for the first time thru */
  94.         
  95.         fprintf(out,"\nchar *rs_strings[]={");
  96.         
  97.         /* apparently the images are right after the strings */
  98.         /* So that's how we know when to stop */
  99.         
  100.         while( q  < r1 ){
  101.             
  102.         if( q == r1-1) *q = '\0';    /* There may be an extra byte 
  103.                                      because the images must start
  104.                                      on a word boundary
  105.                                      */    
  106.         if (oneflag == 0)
  107.              fprintf(out,",\n\"%s\"",q);
  108.             else{
  109.                 oneflag = 0;
  110.                 fprintf(out,"\n\"%s\"",q);
  111.             }
  112.         stradds[nstrings]=(long)(q-head);
  113.          j += 1 + strlen(q);
  114.          
  115. #ifdef GEM         
  116.          progress(0,j);
  117. #endif         
  118.          q += 1 + strlen(q);
  119.         nstrings++;
  120.         if ( nstrings == strmax){
  121.             strmax += MAXSTR;
  122.         stradds= (long *)realloc(stradds,4*strmax);
  123.         nullnes(stradds,"Realloting string adds");
  124.         }
  125.     }
  126.         fprintf(out,"\n};\n");
  127.  
  128.      
  129.     
  130.    
  131.         /* write out the objects next */
  132.         fprintf(out,"\nOBJECT rs_object[]={\n");
  133.         for ( i=0 ; i <rheader.rsh_nobs ; i++){
  134.             
  135. #ifdef GEM            
  136.            progress(1,i+1);
  137. #endif           
  138.         printobj(objs + i);
  139.         if ( i != rheader.rsh_nobs -1 ) fprintf(out,",");        
  140.         fprintf(out,"\n");
  141. }
  142.         fprintf(out,"};\n");    
  143.         
  144.         /*get the offsets of the images so that
  145.            we can get the indices right
  146.          by using findbb()
  147.          */ 
  148.       
  149.               
  150.         for ( i =0 ; i < rheader.rsh_nbb; i++){
  151.          bbadds[i] = (long)(&bitblks[i])-(long)head;    
  152.          /* size is how many words */
  153.          
  154.          size=(bitblks[i].bi_hl)*(bitblks[i].bi_wb)/2;
  155.               where = bitblks[i].bi_pdata;
  156.               
  157.          /* makeimage returns the index in the image array
  158.             cast to a long
  159.             */
  160.          bitblks[i].bi_pdata=makeimage(where,size);
  161.         }
  162.         
  163.         for ( i=0 ; i <rheader.rsh_nib ; i++){
  164.          size=(iconblks[i].ib_hicon)*(iconblks[i].ib_wicon)/16;
  165.          iconblks[i].ib_pmask=makeimage(iconblks[i].ib_pmask,size);
  166.          iconblks[i].ib_pdata=makeimage(iconblks[i].ib_pdata,size);
  167.          iconblks[i].ib_ptext = findstr(iconblks[i].ib_ptext);
  168.         }
  169.                 fprintf(out,"\nBITBLK rs_bitblk[]={\n");
  170.         for ( i=0 ; i <rheader.rsh_nbb ; i++){
  171.             
  172. #ifdef GEM            
  173.         progress(3,i+1);
  174. #endif
  175.         
  176.         printbit( bitblks + i);
  177.         if ( i != rheader.rsh_nbb -1 ) fprintf(out,",");
  178.         fprintf(out,"\n");
  179. }
  180.         fprintf(out,"};\n");
  181.  
  182.                 fprintf(out,"\nICONBLK rs_iconblk[]={\n");
  183.         for ( i=0 ; i <rheader.rsh_nib ; i++){
  184. #ifdef GEM            
  185.         progress(4,i+1);
  186. #endif        
  187.         printicon( iconblks + i);
  188.         if ( i != rheader.rsh_nib -1 ) fprintf(out,",");
  189.         fprintf(out,"\n");
  190. }
  191.         fprintf(out,"};\n");    
  192.               fprintf(out,"\nTEDINFO rs_tedinfo[]={\n");
  193.         for ( i=0 ; i <rheader.rsh_nted ; i++){
  194.             
  195. #ifdef GEM            
  196.         progress(5,i+1);    
  197. #endif        
  198.         printted( teds + i);
  199.         if ( i != rheader.rsh_nted -1 ) fprintf(out,",\n");
  200. }
  201.        fprintf(out,"\n};\n");
  202.        r =( head + rheader.rsh_trindex);
  203.        w = (long)( (char *)objs - head );  
  204.        fprintf(out,"long rs_trindex[]={\n");
  205.        for ( i=0; i < rheader.rsh_ntree ; i++){
  206.            
  207. #ifdef GEM           
  208.        progress(6,i+1);
  209. #endif       
  210.        z = r[i];
  211.        if ( i != rheader.rsh_ntree -1 )
  212.        fprintf(out,"%DL,\n",( z-w )/sizeof(OBJECT));
  213.        else
  214.        fprintf(out,"%DL\n",(z-w)/sizeof(OBJECT));
  215. }
  216.        fprintf(out,"};\n");
  217.        fprintf(out,"rs_frstr[]={\n");
  218.        r = (head + rheader.rsh_frstr);
  219.        for ( i= 0 ; i < rheader.rsh_nstring ; i++){
  220.        
  221. #ifdef GEM           
  222.        progress(7,i+1);    
  223. #endif       
  224.        z = r[i];    
  225.        if( i != rheader.rsh_nstring - 1)fprintf(out,"%DL,\n",findstr(z));
  226.         else fprintf(out,"%DL\n",findstr(z));
  227. }
  228.        fprintf(out,"};\n");
  229.        r = ( head + rheader.rsh_frimg);
  230.        fprintf(out,"long rs_frimg[]={\n");
  231.        for ( i= 0; i < rheader.rsh_nimages ; i++){
  232.            
  233. #ifdef GEM           
  234.         progress(8,i+1);    
  235. #endif        
  236.        if ( i != rheader.rsh_nimages -1)fprintf(out,"%DL,\n",findbb(r[i]));
  237.         else fprintf(out,"%DL\n",findbb(r[i]));
  238.         }
  239.         fprintf(out,"};\n");
  240.  fprintf(out,"struct foobar {\n\tint dummy;\n\tint *image;\n\t} rs_imdope[] = {\n");
  241.        for ( i =0 ; i < nimages ; i++){
  242.        if ( i != nimages -1)fprintf(out,"0,&IMAG%d[0],\n",i);
  243.            else fprintf(out,"0,&IMAG%d[0]\n",i);
  244.         }
  245.        fprintf(out,"};\n");
  246.        fprintf(out,"#define NUM_TI %d\n",rheader.rsh_nted);
  247.        fprintf(out,"#define NUM_BB %d\n",rheader.rsh_nbb);
  248.        fprintf(out,"#define NUM_OBS %d\n",rheader.rsh_nobs);
  249.        fprintf(out,"#define NUM_IB %d\n",rheader.rsh_nib);
  250.        fprintf(out,"#define NUM_FRSTR %d\n",rheader.rsh_nstring);
  251.        fprintf(out,"#define NUM_FRIMG %d\n",rheader.rsh_nimages);
  252.        fprintf(out,"#define NUM_TREE %d\n",rheader.rsh_ntree);
  253.        fprintf(out,"#define NUM_STRINGS %d\n",nstrings); 
  254.        fprintf(out,"#define NUM_IMAGES  %d\n",nimages);    
  255. #ifdef GEM       
  256.        flee() ;
  257. #endif       
  258.  
  259. }
  260.  
  261.